<?php

declare(strict_types=1);

namespace app\libs\wechat;

use EasyWeChat\Pay\Application as PayApplication;
use EasyWeChat\MiniApp\Application as MiniAppApplication;

/**
 * 微信助手类
 */
class UseWechat
{
	protected static $mini_app;
	protected static $wx_pay;

	/**
	 * 获取小程序实例
	 * @return MiniAppApplication
	 */
	public static function getMiniApp(): MiniAppApplication
	{
		if (!self::$mini_app) {
			self::$mini_app = new MiniAppApplication(self::getMiniAppConfig());
		}
		return self::$mini_app;
	}

	public static function getMiniAppConfig()
	{
		return config('wechat.mini_app');
	}

	/**
	 * 获取微信支付实例
	 * @return PayApplication
	 */
	public static function getWxPay(): PayApplication
	{
		if (!self::$wx_pay) {
			self::$wx_pay = new PayApplication(self::getWxPayConfig());
		}
		return self::$wx_pay;
	}

	public static function getWxPayConfig()
	{
		return config('wechat.wx_pay');
	}
}
